import urllib
from urllib import request
from urllib import parse

# urlopen 用于链接url
# URLError : urllib.error.URLError: <urlopen error unknown url type: localhost>
#   解决方式： 添加http:// 协议
# url = "https://www.baidu.com/s?wd=%E5%A4%A7%E6%95%B0%E6%8D%AE"
#                                   %E5%A4%A7%E6%95%B0%E6%8D%AE
# UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-12: ordinal not in range(128)
# url = "https://www.baidu.com/s?wd=大数据"

url = "http://www.baidu.com/s?wd="

encode_res = parse.quote("大数据").encode("utf8")

url += str(encode_res)

# 通过request请求对于的url 获得返回结果
response = request.urlopen(url)

# 对返回结果进行读取，并对读取结果进行转换
print(response.read().decode('utf8'))
